//-----------------------------------------------------------------------
// <copyright file="a_DomPrefMDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_DomPrefMDAOBase
    {
        #region Common methods
        public virtual a_DomPrefM Createa_DomPrefMFromReader(IDataReader reader)
        {
            a_DomPrefM item = new a_DomPrefM();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("DomPrefMID"))) item.DomPrefMID = (int)reader["DomPrefMID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("PrefName"))) item.PrefName = (string)reader["PrefName"];
                if (!reader.IsDBNull(reader.GetOrdinal("PrefValue1"))) item.PrefValue1 = (string)reader["PrefValue1"];
                if (!reader.IsDBNull(reader.GetOrdinal("PrefValue2"))) item.PrefValue2 = (string)reader["PrefValue2"];
                if (!reader.IsDBNull(reader.GetOrdinal("PrefValue3"))) item.PrefValue3 = (string)reader["PrefValue3"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_DomPrefM methods
            
        public virtual void Createa_DomPrefM(a_DomPrefM a_DomPrefM)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomPrefM_ins");
                
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_DomPrefM.DomainID);
                database.AddInParameter(dbCommand, "@PrefName", DbType.AnsiString, a_DomPrefM.PrefName);
                database.AddInParameter(dbCommand, "@PrefValue1", DbType.AnsiString, a_DomPrefM.PrefValue1);
                database.AddInParameter(dbCommand, "@PrefValue2", DbType.AnsiString, a_DomPrefM.PrefValue2);
                database.AddInParameter(dbCommand, "@PrefValue3", DbType.AnsiString, a_DomPrefM.PrefValue3);
                database.AddOutParameter(dbCommand, "@DomPrefMID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_DomPrefM.DomPrefMID = (int)database.GetParameterValue(dbCommand, "@DomPrefMID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_DomPrefM methods
        
        public virtual void Updatea_DomPrefM(a_DomPrefM a_DomPrefM)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomPrefM_upd");            
                
                database.AddInParameter(dbCommand, "@DomPrefMID", DbType.Int32, a_DomPrefM.DomPrefMID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_DomPrefM.DomainID);
                database.AddInParameter(dbCommand, "@PrefName", DbType.AnsiString, a_DomPrefM.PrefName);
                database.AddInParameter(dbCommand, "@PrefValue1", DbType.AnsiString, a_DomPrefM.PrefValue1);
                database.AddInParameter(dbCommand, "@PrefValue2", DbType.AnsiString, a_DomPrefM.PrefValue2);
                database.AddInParameter(dbCommand, "@PrefValue3", DbType.AnsiString, a_DomPrefM.PrefValue3);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_DomPrefM methods
        public virtual void Deletea_DomPrefM(int domPrefMID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomPrefM_del");
                
                database.AddInParameter(dbCommand, "@DomPrefMID", DbType.Int32, domPrefMID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_DomPrefM methods
        
        public virtual a_DomPrefM Geta_DomPrefM(int domPrefMID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomPrefM_sel");
                
                database.AddInParameter(dbCommand, "@DomPrefMID", DbType.Int32, domPrefMID);
                
                a_DomPrefM a_DomPrefM =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_DomPrefM = Createa_DomPrefMFromReader(reader);
                        reader.Close();
                    }
                }
                return a_DomPrefM;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_DomPrefMList methods
        public virtual a_DomPrefMCollection Geta_DomPrefMList(a_DomPrefMColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_DomPrefM_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_DomPrefMCollection a_DomPrefMCollection = new a_DomPrefMCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_DomPrefM a_DomPrefM = Createa_DomPrefMFromReader(reader);
                        a_DomPrefMCollection.Add(a_DomPrefM);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_DomPrefMCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_DomPrefMCollection Geta_DomPrefMList(a_DomPrefMColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_DomPrefMList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}